package bb.lanxing.model.json;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;

import android.os.Parcel;
import android.os.Parcelable;

public class Route implements Parcelable, Serializable {
    public static final Creator<Route> CREATOR = new Creator<Route>() {
        @Override
        public Route createFromParcel(Parcel source) {
            return new Route(source);
        }

        @Override
        public Route[] newArray(int size) {
            return new Route[size];
        }
    };
    public static final int TURN_TYPE_NONE = 0;
    public static final int TURN_TYPE_SLIGHT_LEFT = 1;
    public static final int TURN_TYPE_LEFT = 2;
    public static final int TURN_TYPE_SHARP_LEFT = 3;
    public static final int TURN_TYPE_SLIGHT_RIGHT = 4;
    public static final int TURN_TYPE_RIGHT = 5;
    public static final int TURN_TYPE_SHARP_RIGHT = 6;
    public static final int TURN_TYPE_RAMP_LEFT = 7;
    public static final int TURN_TYPE_RAMP_RIGHT = 8;
    public static final int TURN_TYPE_MERGE = 9;
    public static final int TURN_TYPE_STRAIGHT = 10;
    public static final int TURN_TYPE_UTURN_LEFT = 11;
    public static final int TURN_TYPE_UTURN_RIGHT = 12;
    public static final int TURN_TYPE_ROUNDABOUT_LEFT = 13;
    public static final int TURN_TYPE_ROUNDABOUT_RIGHT = 14;
    public static final int TURN_TYPE_FORK_LEFT = 15;
    public static final int TURN_TYPE_FORK_RIGHT = 16;
    @JSONField(serialize = false)
    private List<RouteStep> allSteps;
    private Bounds bounds;
    private String copyrights;
    private RouteLeg[] legs;
    @JSONField(name = "overview_path")
    private RoutePoint[] overviewPath;
    @JSONField(name = "overview_polyline")
    private RoutePolyline overviewPolyline;
    private PlanSource planSource;
    private String summary;
    private String[] warnings;

    public Route() {
        this.planSource = PlanSource.Google;
    }

    protected Route(Parcel in2) {
        this.planSource = PlanSource.Google;
        this.bounds = (Bounds) in2.readParcelable(Bounds.class.getClassLoader());
        this.copyrights = in2.readString();
        this.overviewPath = (RoutePoint[]) in2.createTypedArray(RoutePoint.CREATOR);
        this.overviewPolyline = (RoutePolyline) in2.readParcelable(RoutePolyline.class.getClassLoader());
        this.summary = in2.readString();
        this.warnings = in2.createStringArray();
        this.legs = (RouteLeg[]) in2.createTypedArray(RouteLeg.CREATOR);
        this.allSteps = in2.createTypedArrayList(RouteStep.CREATOR);
        int readInt = in2.readInt();
        this.planSource = readInt == -1 ? null : PlanSource.values()[readInt];
    }

    public static int parseManeuverType(String maneuver) {
        if (maneuver == null) {
            return TURN_TYPE_NONE;
        }

        switch (maneuver) {
        case RouteStep.MANEUVER_SLIGHT_LEFT -> {
            return TURN_TYPE_SLIGHT_LEFT;
        }
        case RouteStep.MANEUVER_UTURN_LEFT -> {
            return TURN_TYPE_UTURN_LEFT;
        }
        case RouteStep.MANEUVER_RAMP_RIGHT -> {
            return TURN_TYPE_RAMP_RIGHT;
        }
        case RouteStep.MANEUVER_RAMP_LEFT -> {
            return TURN_TYPE_RAMP_LEFT;
        }
        case RouteStep.MANEUVER_SHARP_RIGHT -> {
            return TURN_TYPE_SHARP_RIGHT;
        }
        case RouteStep.MANEUVER_ROUNDABOUT_LEFT -> {
            return TURN_TYPE_ROUNDABOUT_LEFT;
        }
        case RouteStep.MANEUVER_RIGHT -> {
            return TURN_TYPE_RIGHT;
        }
        case RouteStep.MANEUVER_UTURN_RIGHT -> {
            return TURN_TYPE_UTURN_RIGHT;
        }
        case RouteStep.MANEUVER_LEFT -> {
            return TURN_TYPE_LEFT;
        }
        case RouteStep.MANEUVER_MERGE -> {
            return TURN_TYPE_MERGE;
        }
        case RouteStep.MANEUVER_ROUNDABOUT_RIGHT -> {
            return TURN_TYPE_ROUNDABOUT_RIGHT;
        }
        case RouteStep.MANEUVER_SLIGHT_RIGHT -> {
            return TURN_TYPE_SLIGHT_RIGHT;
        }
        case RouteStep.MANEUVER_SHARP_LEFT -> {
            return TURN_TYPE_SHARP_LEFT;
        }
        case RouteStep.MANEUVER_FORK_RIGHT -> {
            return TURN_TYPE_FORK_RIGHT;
        }
        case RouteStep.MANEUVER_FORK_LEFT -> {
            return TURN_TYPE_FORK_LEFT;
        }
        case RouteStep.MANEUVER_STRAIGHT -> {
            return TURN_TYPE_STRAIGHT;
        }
        }

        return TURN_TYPE_NONE;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("route[");
        sb.append(this.summary);
        sb.append("  path = ");
        RoutePolyline routePolyline = this.overviewPolyline;
        Object obj = "null";// b.l;
        sb.append(routePolyline == null ? obj : routePolyline.getPoints());
        sb.append(" legs = ");
        RouteLeg[] routeLegArr = this.legs;
        if (routeLegArr != null) {
            obj = routeLegArr.length;
        }
        sb.append(obj);
        sb.append(" - ");
        sb.append(this.copyrights);
        sb.append("]");
        return sb.toString();
    }

    public List<RouteStep> getAllSteps() {
        if (this.allSteps == null) {
            if (this.legs.length == 0) {
                this.allSteps = new ArrayList(0);
            } else {
                this.allSteps = new ArrayList();
                for (RouteLeg routeLeg : this.legs) {
                    this.allSteps.addAll(Arrays.asList(routeLeg.getSteps()));
                }
            }
        }
        return this.allSteps;
    }

    public Bounds getBounds() {
        return this.bounds;
    }

    public void setBounds(Bounds bounds) {
        this.bounds = bounds;
    }

    public String getCopyrights() {
        return this.copyrights;
    }

    public void setCopyrights(String copyrights) {
        this.copyrights = copyrights;
    }

    public RoutePoint[] getOverviewPath() {
        return this.overviewPath;
    }

    public void setOverviewPath(RoutePoint[] overviewPath) {
        this.overviewPath = overviewPath;
    }

    public RoutePolyline getOverviewPolyline() {
        return this.overviewPolyline;
    }

    public void setOverviewPolyline(RoutePolyline overviewPolyline) {
        this.overviewPolyline = overviewPolyline;
    }

    public String getSummary() {
        return this.summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String[] getWarnings() {
        return this.warnings;
    }

    public void setWarnings(String[] warnings) {
        this.warnings = warnings;
    }

    public RouteLeg[] getLegs() {
        return this.legs;
    }

    public void setLegs(RouteLeg[] legs) {
        this.legs = legs;
    }

    public PlanSource getPlanSource() {
        return this.planSource;
    }

    public void setPlanSource(PlanSource planSource) {
        this.planSource = planSource;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.bounds, flags);
        dest.writeString(this.copyrights);
        dest.writeTypedArray(this.overviewPath, flags);
        dest.writeParcelable(this.overviewPolyline, flags);
        dest.writeString(this.summary);
        dest.writeStringArray(this.warnings);
        dest.writeTypedArray(this.legs, flags);
        dest.writeTypedList(this.allSteps);
        PlanSource planSource = this.planSource;
        dest.writeInt(planSource == null ? -1 : planSource.ordinal());
    }

    public enum PlanSource {
        Google, Baidu
    }

    public static class Bounds implements Parcelable {
        public static final Creator<Bounds> CREATOR = new Creator<Bounds>() {
            @Override
            public Bounds createFromParcel(Parcel source) {
                return new Bounds(source);
            }

            @Override
            public Bounds[] newArray(int size) {
                return new Bounds[size];
            }
        };
        RoutePoint northEast;
        RoutePoint northeast;
        RoutePoint southWest;
        RoutePoint southwest;

        public Bounds() {
        }

        protected Bounds(Parcel in2) {
            this.northEast = (RoutePoint) in2.readParcelable(RoutePoint.class.getClassLoader());
            this.southWest = (RoutePoint) in2.readParcelable(RoutePoint.class.getClassLoader());
            this.northeast = (RoutePoint) in2.readParcelable(RoutePoint.class.getClassLoader());
            this.southwest = (RoutePoint) in2.readParcelable(RoutePoint.class.getClassLoader());
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public RoutePoint getNorthEast() {
            return this.northEast;
        }

        public void setNorthEast(RoutePoint northEast) {
            this.northEast = northEast;
        }

        public RoutePoint getSouthWest() {
            return this.southWest;
        }

        public void setSouthWest(RoutePoint southWest) {
            this.southWest = southWest;
        }

        public RoutePoint getNortheast() {
            return this.northeast;
        }

        public void setNortheast(RoutePoint northeast) {
            this.northeast = northeast;
        }

        public RoutePoint getSouthwest() {
            return this.southwest;
        }

        public void setSouthwest(RoutePoint southwest) {
            this.southwest = southwest;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeParcelable(this.northEast, flags);
            dest.writeParcelable(this.southWest, flags);
            dest.writeParcelable(this.northeast, flags);
            dest.writeParcelable(this.southwest, flags);
        }
    }
}
